<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">

    <script src="/static/layui/layui.js"></script>
    <script src="/static/js/jquery.min.js"></script>
</head>
<body style="height: 100%">

<form class="layui-form" action="" autocomplete="new-password" style="margin-top: 10px">
    <div class="layui-form-item" >
        <label class="layui-form-label">一级分类名称</label>
        <div class="layui-input-block" style="padding-left: 10px;padding-right: 10px">
            <select name="stIdOne" id="stIdOne" lay-verify="required" lay-filter="stIdOne">
                <option value="-1">请选择一级分类</option>
                <c:forEach items="${typeOneList}" var="type">
                    <option value="${type.stId}">${type.stName}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">二级分类名称</label>
        <div class="layui-input-block" style="padding-left: 10px;padding-right: 10px">
            <input type="text" name="stName"  value=""  lay-verify="required" placeholder="请输入二级分类名称"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block" style="padding-left: 10px;padding-right: 10px">
            <input type="text" name="stSort"  value=""  lay-verify="required|number" placeholder="请输入数字"  class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn" class="layui-btn" lay-submit lay-filter="commit">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(['upload','jquery','form','util'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,form = layui.form;

        //监听提交
        form.on('submit(commit)', function(data){

            var stIdOne = $("#stIdOne").val();
            if (stIdOne == -1){
                layer.alert("请选择一级分类");
                return false;
            }

            $.ajax({
                url : '/manage/type/addTwo',
                type : 'post',
                dataType : 'json',
                data : data.field,
                success : function (data) {
                    if (data.code==200){
                        layer.msg(data.msg,{icon: 1, time: 500},function () {
                            layer.close();
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

    });
</script>

</body>
</html>
